//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口;

public class demo_2134 {
    public demo_2134() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 0, 1, 1, 0, 0};
        System.out.println(minSwaps(nums));
    }

    public static int minSwaps(int[] nums) {
        int n = nums.length;
        int count = 0;
        int k = 0;

        for(int num : nums) {
            if (num == 1) {
                ++k;
            }
        }

        int left = n - k;

        for(int i = left; i < n; ++i) {
            if (nums[i] == 0) {
                ++count;
            }
        }

        int min = count;

        for(int num : nums) {
            if (num == 0) {
                ++count;
            }

            if (nums[left] == 0) {
                --count;
            }

            left = (left + 1) % n;
            min = Math.min(min, count);
        }

        return min;
    }
}
